package cn.ibizlab.odoo.core.odoo_hr.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage;
import cn.ibizlab.odoo.core.odoo_hr.domain.Hr_recruitment_stage;
import cn.ibizlab.odoo.core.odoo_hr.filter.Hr_recruitment_stageSearchContext;
import cn.ibizlab.odoo.core.odoo_hr.service.IHr_recruitment_stageService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[招聘阶段] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Hr_recruitment_stageServiceImpl implements IHr_recruitment_stageService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Ihr_recruitment_stageClientService hr_recruitment_stageClientService;

    @Override
    public Hr_recruitment_stage get(Integer id) {
        Ihr_recruitment_stage clientModel = hr_recruitment_stageClientService.createModel();
        clientModel.setId(id);
        hr_recruitment_stageClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Hr_recruitment_stage get(Hr_recruitment_stage hr_recruitment_stage) {
        Hr_recruitment_stage rethr_recruitment_stage = this.get(hr_recruitment_stage.getId()) ;
    	BeanCopier copier=BeanCopier.create(rethr_recruitment_stage.getClass(), hr_recruitment_stage.getClass(), false);
        copier.copy(rethr_recruitment_stage, hr_recruitment_stage, null);
        return hr_recruitment_stage ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //hr_recruitment_stageClientService.removeBatch(hr_recruitment_stages) ;

    }

    @Override
    public boolean create(Hr_recruitment_stage hr_recruitment_stage) {
        boolean bOk = false ;
        Ihr_recruitment_stage clientModel = this.convert2Model(hr_recruitment_stage,null);
        hr_recruitment_stageClientService.create(clientModel) ;
        this.convert2Domain(clientModel,hr_recruitment_stage);
        bOk = true ;

        return bOk ;
    }

    @Override
    public boolean update(Hr_recruitment_stage hr_recruitment_stage) {
        boolean bOk = false ;
        Ihr_recruitment_stage clientModel = this.convert2Model(hr_recruitment_stage,null);
        hr_recruitment_stageClientService.update(clientModel) ;
        this.convert2Domain(clientModel,hr_recruitment_stage) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Hr_recruitment_stage> hr_recruitment_stages, int batchSize) {

                        //hr_recruitment_stageClientService.createBatch(hr_recruitment_stages,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Ihr_recruitment_stage clientModel = hr_recruitment_stageClientService.createModel();
        clientModel.setId(id);
        hr_recruitment_stageClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Hr_recruitment_stage> hr_recruitment_stages, int batchSize) {

        //hr_recruitment_stageClientService.updateBatch(hr_recruitment_stages,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Hr_recruitment_stage> searchDefault(Hr_recruitment_stageSearchContext context) {
        List<Hr_recruitment_stage> list = new ArrayList<Hr_recruitment_stage>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage> clientModelList = hr_recruitment_stageClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_recruitment_stage>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据工作岗位查询
     */
    @Override
    public Page<Hr_recruitment_stage> selectByOdoo_job(Integer id){
        Hr_recruitment_stageSearchContext context = new Hr_recruitment_stageSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_recruitment_stage> list = new ArrayList<Hr_recruitment_stage>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage> clientModelList = hr_recruitment_stageClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_recruitment_stage>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据EMail模板查询
     */
    @Override
    public Page<Hr_recruitment_stage> selectByOdoo_template(Integer id){
        Hr_recruitment_stageSearchContext context = new Hr_recruitment_stageSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_recruitment_stage> list = new ArrayList<Hr_recruitment_stage>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage> clientModelList = hr_recruitment_stageClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_recruitment_stage>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Hr_recruitment_stage> selectByOdoo_create(Integer id){
        Hr_recruitment_stageSearchContext context = new Hr_recruitment_stageSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_recruitment_stage> list = new ArrayList<Hr_recruitment_stage>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage> clientModelList = hr_recruitment_stageClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_recruitment_stage>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Hr_recruitment_stage> selectByOdoo_write(Integer id){
        Hr_recruitment_stageSearchContext context = new Hr_recruitment_stageSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Hr_recruitment_stage> list = new ArrayList<Hr_recruitment_stage>();
        Page<cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage> clientModelList = hr_recruitment_stageClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Ihr_recruitment_stage clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Hr_recruitment_stage>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Ihr_recruitment_stage convert2Model(Hr_recruitment_stage domain , Ihr_recruitment_stage model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = hr_recruitment_stageClientService.createModel() ;
        }

         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getRequirementsDirtyFlag())
            model.setRequirements(domain.getRequirements());
         if(domain.getLegend_normalDirtyFlag())
            model.setLegend_normal(domain.getLegend_normal());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getFoldDirtyFlag())
            model.setFold(domain.getFold());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getLegend_doneDirtyFlag())
            model.setLegend_done(domain.getLegend_done());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getLegend_blockedDirtyFlag())
            model.setLegend_blocked(domain.getLegend_blocked());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getTemplate_id_textDirtyFlag())
            model.setTemplate_id_text(domain.getTemplate_id_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getJob_id_textDirtyFlag())
            model.setJob_id_text(domain.getJob_id_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getJob_idDirtyFlag())
            model.setJob_id(domain.getJob_id());
         if(domain.getTemplate_idDirtyFlag())
            model.setTemplate_id(domain.getTemplate_id());
        return model ;
    }

    public Hr_recruitment_stage convert2Domain( Ihr_recruitment_stage model ,Hr_recruitment_stage domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Hr_recruitment_stage();
        }

        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getRequirementsDirtyFlag())
            domain.setRequirements(model.getRequirements());
        if(model.getLegend_normalDirtyFlag())
            domain.setLegend_normal(model.getLegend_normal());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getFoldDirtyFlag())
            domain.setFold(model.getFold());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getLegend_doneDirtyFlag())
            domain.setLegend_done(model.getLegend_done());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getLegend_blockedDirtyFlag())
            domain.setLegend_blocked(model.getLegend_blocked());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getTemplate_id_textDirtyFlag())
            domain.setTemplate_id_text(model.getTemplate_id_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getJob_id_textDirtyFlag())
            domain.setJob_id_text(model.getJob_id_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getJob_idDirtyFlag())
            domain.setJob_id(model.getJob_id());
        if(model.getTemplate_idDirtyFlag())
            domain.setTemplate_id(model.getTemplate_id());
        return domain ;
    }


}
